package remoting;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import object.Note;

import com.google.gdata.client.GoogleService;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;

public class GoogleNoteService {

    public List<Note> getMyNotes() {
        List<Note> resultList = new ArrayList<Note>();
        try {
            URL feedUrl = new URL("http://www.google.com/notebook/feeds/08505853622322887714/notebooks/BDR-WDAoQkvCCr_Mj");
            GoogleService myService = new GoogleService("notebook", "My Notebook");

            // Send the request and receive the response:
            Feed myFeed = myService.getFeed(feedUrl, Feed.class);

            for (Entry entry : myFeed.getEntries()) {
                Note newNote = new Note();
                newNote.setText(entry.getTitle().getPlainText());
                newNote.setUpdateTime(entry.getUpdated().toUiString());
                resultList.add(newNote);
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return resultList;
    }
}
